Ext.require('Ext.dd.DDProxy');
Ext.require('Ext.dd.DropZone');
Ext.require('Ext.tip.QuickTipManager');
Ext.onReady(function(){
	Ext.override(Ext.dd.DDProxy, {
		startDrag: function(){
			var dragEl = Ext.get(this.getDragEl());
			var el = Ext.get(this.getEl());
			dragEl.applyStyles({border:'','z-index':2000});
			dragEl.update(el.dom.innerHTML);
			dragEl.addCls(el.dom.className + ' dd-proxy');
		},
		
		onDragOver: function(e, targetId){
			if(targetId === 'dd1-ct' || targetId === 'dd2-ct'){
				var target = Ext.get(targetId);
				this.lastTarget = target;
				target.addCls('highlight');
			}
		},
		
		onDragOut: function(e, targetId){
			if(targetId === 'dd1-ct' || targetId === 'dd2-ct'){
				var target = Ext.get(targetId);
				this.lastTarget = null;
				target.removeCls('highlight');
			}
		},
		
		endDrag: function() {
			var dragEl = Ext.get(this.getDragEl());
			var el = Ext.get(this.getEl());
			if(this.lastTarget){
				Ext.get(this.lastTarget).appendChild(el);
				el.applyStyles({position:'', width: ''});
			} else {
				el.applyStyles({position: 'absolute'});
				el.setXY(dragEl.getXY());
				el.setWidth(dragEl.getWidth());
			}
			Ext.get('dd1-ct').removeCls('highlight');
			Ext.get('dd2-ct').removeCls('highlight');
		}
	});
	Ext.select('.dd-item').each(function(item){
	
		var dropZone = new Ext.dd.DropZone('dd1-ct', {ddGroup: 'group'});
		var dropZone = new Ext.dd.DropZone('dd2-ct', {ddGroup: 'group'});
		
		try{
			item.dd = new Ext.dd.DDProxy(item.id, 'group');
		}catch(e){
			alert(e.message);
		}
	});
});